package com.duoduo.common.util.postProcessor;

import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

/**
 * 定义: 数据聚合平台切表工具
 */
public class FusionSqlSessionFactoryBeanPostProcessor implements BeanPostProcessor {
	
	private Interceptor fusionInterceptor;
	public FusionSqlSessionFactoryBeanPostProcessor() {
		fusionInterceptor = new FusionInterceptor();
	}

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (bean instanceof SqlSessionFactory) {
            SqlSessionFactory nowBean = (SqlSessionFactory) bean;
            nowBean.getConfiguration().addInterceptor(fusionInterceptor);
        }
        return bean;
    }

	@Override
	public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
		return bean;
	}
    
}